info = {'name': 'xiaowang', 'id': 100, 'sex':'f', 'address': '河南省'}
print(info['name'])

age = info.get('sex')
print(age)                  # age 键不存在返回 None
print(type(age))
age = info.get('age', 20)   # # age 键不存在返回值 20
print(age)

print('-'*20)
# 修改
info = {'name': 'xiaowang', 'id': 100, 'sex':'f', 'address': '河南省'}
new_id = input('请输入新学号：')
info['id'] = int(new_id)
print(info['id'])

print('-'*20)
# 添加
info = {'name': 'xiaowang', 'sex':'f', 'address': '河南省'}
print(info)
new_id = input('输入id：')
info['id'] = new_id
print(info)
print(info['id'])

print('-'*20)
# 删除
info = {'name': 'xiaowang', 'sex':'f', 'address': '河南省'}
print(info)
# del
print('删除前：%s'%info['name'])
del info['name']
print(info)
# clear
info.clear()
print(info)

print('-'*20)
# 个数
info = {'name': 'xiaowang', 'sex':'f', 'address': '河南省'}
lenth = len(info)
print(lenth)

# 键视图
info = {'name': 'xiaowang', 'sex':'f', 'address': '河南省'}
print(info.keys())
# 值视图
print(info.values())

print('-'*20)
# 元素视图
info = {'name': 'xiaowang', 'sex':'f', 'address': '河南省'}
print(info.items())

print('-'*200)
# 遍历字典
info = {'name': 'xiaowang', 'id': 100, 'sex':'f', 'address': '河南省'}
# 键
for key in info.keys():
    print(key, end=' ')
print()
# 值
for value in info.values():
    print(value, end=' ')
print()
# 元素
for item in info.items():
    print(item, end=' ')
print()
# 键值对
for key,value in info.items():
    print("key = %s, value = %s"%(key, value), end='    ')

print()
for key,value in info.items():
    print((key, value), end='    ')
